import json
import requests
import allure
# from selenium.webdriver.support import wait


devUrl = "http://dohko-public-mis-api-web-non-auth.tiaofangzi.com"
dohkoUrl = "http://dohko.nonauth.mis.tiaofangzi.com"
publicUrl = "https://public-mis.tiaofangzi.com"
dohkoUrl1 = "https://dohko-api-public.tiaofangzi.com"
dohkoUrl2 = "https://dohko-tfz-web.tiaofangzi.com"
dohkoUrl3 = "https://dohko-fe-mis-noauth.tiaofangzi.com"

@allure.step("dev_post_校验接口code")
def post_printDev(rpb, caseName=""):
    print("接口返回状态：", rpb)
    # print("code：", rpb.json())
    print("返回参数", json.dumps(rpb.json(), indent=2, ensure_ascii=False))
    # print("code：", rpb.json()["success"])
    msg1 = "执行成功"
    msg2 = "成功"
    msg3 = '"催办成功"'
    if caseName == "needToken":
        print(rpb.json()["header"]["msg"])
        return_msg = rpb.json()["header"]["msg"]
        assert return_msg == msg1 or return_msg == msg2, "接口请求失败，回参不正确。！"
    elif caseName == "dls-yue":
        print(rpb.json()["message"])
        return_msg = rpb.json()["message"]
        assert return_msg == msg1
    elif caseName == "cuiyicui":
        result = json.dumps(rpb.json()["msg"], ensure_ascii=False)
        assert result == '"催办成功"'
    else:
        #返回的msg
        return_msg = rpb.json()["msg"]
        #返回的code
        return_code = rpb.json()["code"]
        assert return_msg == msg1 or return_msg == msg2 or return_code == "000", "接口请求失败，回参不正确。！"


"""调试返回用的函数"""
def post_test_printDev(rpb, caseName=""):
    print("返回参数", json.dumps(rpb.json(), indent=2, ensure_ascii=False))


@allure.step("dev_post_校验接口code")
def get_printDev(rpb, caseName=""):
    print("接口返回状态：", rpb)
    # print("code：", rpb.json())
    print("返回参数", json.dumps(rpb.json(), indent=2, ensure_ascii=False))
    # print("code：", rpb.json()["success"])
    msg1 = "执行成功"
    msg2 = "成功"
    msg3 = '"催办成功"'
    if caseName == "needToken":
        print(rpb.json()["header"]["msg"])
        return_msg = rpb.json()["header"]["msg"]
        assert return_msg == msg1 or return_msg == msg2, "接口请求失败，回参不正确。！"
    elif caseName == "cuiyicui":
        result = json.dumps(rpb.json()["msg"], ensure_ascii=False)
        assert result == '"催办成功"'
    elif caseName == "emp":
        #返回的message
        return_message = rpb.json()["message"]
        print (return_message)
        assert return_message == msg1, "接口请求失败！"
    else:
        #返回的msg
        return_msg = rpb.json()["msg"]
        #返回的code
        return_code = rpb.json()["code"]
        assert return_msg == msg1 or return_msg == msg2 or return_code == "000", "接口请求失败，回参不正确。！"



@allure.step("dev_get_校验接口code")
def get_printDev_test(rpb):
    print("接口返回状态：", rpb)
    print("code：", rpb.json())
    print("code：", json.dumps(rpb.json(), indent=2, ensure_ascii=False))
    # print("code：", rpb.json()["success"])
    # code = rpb.json()["success"]
    # assert code is True
    # msg1 = "执行成功"
    # msg2 = "成功"
    # return_msg = rpb.json()["msg"]
    # assert return_msg == msg1

def user_token():
    """返回一个用户的新token"""
    url = "https://dohko.login.internal.tiaofangzi.com/logOnDynamicCodeMobile"
    parm = {
        "phoneNumber": "13521653526",
        "dynamicCode": "000000",
        "plat": "1",
    }
    return_token = requests.post(url, params=parm)
    print("获取的的新token", return_token.json()["data"]["access_token"])
    token = return_token.json()["data"]["access_token"]
    return "access_token=" + token

print("123123:",user_token()[13: ])

